/**
 * Copyright (C), 2015-2020, XXX有限公司
 * FileName: TrueOrFalse
 * Author:   zhuqifeng
 * Date:     2020/11/12 14:59
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.xlkj.ms.tools.core.utils;

/**
 *
 * @author zhuqifeng
 * @date 2021/11/10 13:51
 * @package com.xlkj.ms.tools.core.utils
 */
public enum TrueOrFalse {
    /** false */
    FALSE("0", 0, "false"),
    /** true */
    TRUE("1", 1, "true"),
    ;

    private final String stringCode;

    private final int intCode;

    private final String msg;

    TrueOrFalse(final String stringCode, final int intCode, final String msg) {
        this.stringCode = stringCode;
        this.intCode = intCode;
        this.msg = msg;
    }

    public static TrueOrFalse getInstanceByCode(String code){
        for (TrueOrFalse trueOrFalse : TrueOrFalse.values()){
            if(StringUtils.isEquals(trueOrFalse.getStringCode(),code)){
                return trueOrFalse;
            }
        }
        return null;
    }

    public static TrueOrFalse getInstanceByCode(int code){
        for (TrueOrFalse trueOrFalse : TrueOrFalse.values()){
            if(trueOrFalse.getIntCode()==code){
                return trueOrFalse;
            }
        }
        return null;
    }

    public static TrueOrFalse getInstanceByCode(boolean code){
        if(code){
            return TRUE;
        }
        return FALSE;
    }

    /**
     * 根据字符串类型的true，false来获取枚举实例
     * @param trueOrFalseString
     * @return
     */
    public static TrueOrFalse getInstanceByMsg(String trueOrFalseString){
        for (TrueOrFalse trueOrFalse : TrueOrFalse.values()){
            if(StringUtils.isEquals(trueOrFalse.getMsg(),trueOrFalseString)){
                return trueOrFalse;
            }
        }
        return null;
    }

    public static boolean isTrueOrFalseInstance(String code){
        return null!=getInstanceByCode(code);
    }

    /**
     * 判断是否是true
     * @param code
     * @return
     */
    public static boolean isTrue(String code){
        return StringUtils.isEquals(TRUE.getStringCode(), code);
    }

    /**
     * 判断是否是true
     * @param code
     * @return
     */
    public static boolean isTrue(int code){
        return StringUtils.isEquals(TRUE.getStringCode(), ""+code);
    }

    public String getStringCode() {
        return stringCode;
    }

    public String getMsg() {
        return msg;
    }

    public int getIntCode() {
        return intCode;
    }
}
